﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using GameEngine.Model.Data;
using System.Windows.Media.Imaging;
using SLPerlinNoise;
using SilverlightResources;
using GameEngine.Clients.Silverlight;
using MapEngine;
using System.Collections.Generic;
using GameEngine.Model.Data.implementation;
using GameEngine.Clients.Silverlight.View.Components;

namespace ExampleSilverlight
{
    public class MyGame
    {
        public static IGameVO<int> CreateGame()
        {
            //TODO meter isto em config file
            IGameVO<int> game = new GameVO<int>(new GameVOId("1"))
            {
                Name = "myGame",
                MinHeight = -10,
                MaxHeight = 50,
            };
            ILevelVO<int> level = new LevelVO<int>(new LevelVOId("lvl1"))
            {
                Name = "myUni"
            };
            MapVO<int> map = new MapVO<int>("myMap")
            {
            };
            map.CreateTiles(new Point(40, 40));
            PerlinNoise3D.GenerateHeightsFromPerlin(map.Tiles, new Point(15, 5), 0.025f, 1, 0.5f, 2, 1, game.MinHeight, game.MaxHeight);
            //map.Tiles[5][5].Height = 50;
            map.Camera.Position = new Point(20, 20);//20 20
            map.Camera.Scale = 3f;
            WorldVO<int> world = new WorldVO<int>(new WorldVOId("myWorld"))
            {
                Map = map,
            };
            level.Worlds.Add(world);
            game.Levels.Add(level);
            game.CurrentLevel = 0;
            game.LevelOrder.Add(0, level.Id);

            //Add Views
            #region Views

            var malePeasantView = SpriteMaleAndFemale.createMaleView(SilverlightModelFacade.Instance.CreateNewId(), "male");
            var houseView = MyShapes.createHouse(SilverlightModelFacade.Instance.CreateNewId(),"house",new Point3d(new Point(20,20),15),new Point3d(new Point(22,22),10),Colors.White,Colors.Red);
            var fieldView = MyShapes.createView(SilverlightModelFacade.Instance.CreateNewId(), "field", new List<IShapeVO>(){
                new ShapeVO(new ShapeVOId(MyShapes.NewShapeID), new ShapeTypeVOId(ItemUC.ShapeTypeCube))
            {
                Position = new MapEngine.Point3d(),
                TypeModifiers = ItemUC.createCubeModifiers(new Point3d(new Point(20,20),0.1f), new Point3d(new Point(30,30),0), Colors.Yellow)
            }});
            var arvoreView = MyShapes.createTree(SilverlightModelFacade.Instance.CreateNewId(), "tree", new Point3d(new Point(5, 5), 10), new Point(20, 20));
            var ervaView = MyShapes.createGrass(SilverlightModelFacade.Instance.CreateNewId(), "grass", new Point(5, 5));
            //var seaView = MyShapes.createView(SilverlightModelFacade.Instance.CreateNewId(), "sea", new List<IShapeVO>(){
            //    new ShapeVO(new ShapeVOId(MyShapes.NewShapeID), new ShapeTypeVOId(ItemUC.ShapeTypeCube))
            //{
            //    Position = new MapEngine.Point3d(),
            //    TypeModifiers = ItemUC.createCubeModifiers(new Point3d(new Point(20,20),0), new Point3d(new Point(400,400),0), Color.FromArgb(100,0,0,255))
            //}});

            //game.Views.Add(seaView);
            game.Views.Add(malePeasantView);
            game.Views.Add(houseView);
            game.Views.Add(fieldView);
            game.Views.Add(ervaView);
            game.Views.Add(arvoreView);
            #endregion

            //world.Map.SimpleViews.Add(seaView.Id);

            #region Types
            //Add ThingTypes

            ThinkingThingTypeVO<int> humanType = new ThinkingThingTypeVO<int>(new ThingTypeVOId(SilverlightModelFacade.Instance.CreateNewId()) { Name = "humanMale" })
            {
                ViewId = malePeasantView.Id
            };
            game.ThingTypes.Add(humanType);

            ThingTypeVO<int> houseTypeVO = new ThingTypeVO<int>(new ThingTypeVOId(SilverlightModelFacade.Instance.CreateNewId()) { Name = "house" })
            {
                ViewId = houseView.Id
            };
            game.ThingTypes.Add(houseTypeVO);

            ThingTypeVO<int> fieldTypeVO = new ThingTypeVO<int>(new ThingTypeVOId(SilverlightModelFacade.Instance.CreateNewId()) { Name = "field" })
            {
                ViewId = fieldView.Id
            };
            game.ThingTypes.Add(fieldTypeVO);

            ThingTypeVO<int> ervaType = new ThingTypeVO<int>(new ThingTypeVOId(SilverlightModelFacade.Instance.CreateNewId()) { Name = "grass" })
            {
                ViewId = ervaView.Id
            };
            game.ThingTypes.Add(ervaType);

            ThingTypeVO<int> arvoreType = new ThingTypeVO<int>(new ThingTypeVOId(SilverlightModelFacade.Instance.CreateNewId()) { Name = "tree" })
            {
                ViewId = arvoreView.Id
            };
            game.ThingTypes.Add(arvoreType);
            #endregion

            #region Items
            ///     Items

            //human
            ThingVO<int> presa1 = new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Human" }, humanType.Id)
            {
                Position = new MapEngine.Point3d(new Point(17, 27), 0),
                Direction = new Point(0, -1),//south
                //Energy = 50,
                //Food = typeof(VegetalVO).GUID
            };
            world.Items.Add(presa1);

            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "House" }, houseTypeVO.Id)
            {
                Position = new MapEngine.Point3d(new Point(17, 30), 0),
            });

            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Field" }, fieldTypeVO.Id)
            {
                Position = new MapEngine.Point3d(new Point(17, 25), 0),
            });

            //erva
            ThingVO<int> erva1 = new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(20, 25), 0),
            };
            world.Items.Add(erva1);
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(17, 17), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass"}, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(24, 17), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(25, 19), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(23, 12), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(18, 23), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(23, 18), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(24, 15), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Grass" }, ervaType.Id)
            {
                Position = new MapEngine.Point3d(new Point(25, 15), 0),
            });

            //arvore
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Tree" }, arvoreType.Id)
            {
                Position = new MapEngine.Point3d(new Point(25, 17), 0),
            });
            world.Items.Add(new ThingVO<int>(new ThingVOId<int>(SilverlightModelFacade.Instance.CreateNewId()) { Name = "Tree" }, arvoreType.Id)
            {
                Position = new MapEngine.Point3d(new Point(18, 19), 0),
            });
            #endregion
            
            return game;
        }
    }
}
